<%@page import="com.sun.java.swing.plaf.windows.resources.windows"%>
<%@page import="sun.security.util.Password"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*,java.util.*"%>
<%@ include file="dbconn.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>合同管理系统</title>

</head>
<body>
<script type="text/javascript">
function disp_alert()
{
	alert("用户名或密码错误，请重新输入！")
}
</script>
<%  
    String username=new String(request.getParameter("username"));  
    String password=new String(request.getParameter("password"));  
    try {  
        // 加载数据库驱动，注册到驱动管理器  
        Class.forName("com.mysql.jdbc.Driver");  
        // 数据库连接字符串  
        String url = "jdbc:mysql://localhost:3306/contract";  
        // 数据库用户名  
        String usename = "root";  
        // 数据库密码  .getBytes("UTF-8"),"ISO8859-1"
        String psw = "root";  
        // 创建Connection连接  
        Connection conn = DriverManager.getConnection(url,usename,psw);  
        // 判断 数据库连接是否为空  
        if(conn != null){             
            String sql="select * from t_user where username='"+username+"' and password='"+ password + "'";  
            Statement stmt = conn.createStatement();  
            ResultSet rs=stmt.executeQuery(sql);  
            if(rs.next()){  
                response.sendRedirect("main.jsp");                
            }else{          	
            	
            	
            	out.println("<script>alert('用户名或密码错误，请重新输入！');</script>");
            	%>
            	

            	<a href="javascript:history.back()">返回</a>  
            	<%  
            	 
            }             
            // 输出连接信息  
           // out.println("数据库连接成功！");  
            // 关闭数据库连接  
            conn.close();  
        }else{  
            // 输出连接信息  
            out.println("数据库连接失败！");                          
        }  
    } catch (ClassNotFoundException e) {  
        e.printStackTrace();  
    } catch (SQLException e) {  
        e.printStackTrace();  
    }  
%>
</body>
</html>